function promiseRace(promises) {
  return new Promise((resolve, reject) => {
    if (!Array.isArray(promises)) return reject(new Error("必须是个数组!"));
    // map其实是一起运行的，中间间隔的时间其实很短，所以这里的处理时间还是看，resolve 的处理时间长短
    promises.map((p) => {
      p.then(
        (data) => {
          resolve(data);
        },
        (err) => {
          reject(err);
        }
      );
    });
  });
}

const promises = Array(10).fill(
  new Promise((resolve, reject) => {
    const rd = Math.random();
    setTimeout(() => {
      resolve(rd);
    }, rd * 10000);
  })
);

promiseRace(promises).then((data) => {
  console.log(data);
});
